<?php 
	//ini_set('display_errors', false);
	error_reporting(0);
?>
<div class="clear_both"></div>
<div class="main_container">
<div class="div_block">Payroll Period: 
	<select id="period" name="period">
	<?php foreach($periods as $p):?>
		<option value="<?php echo $p->id?>"><?php echo DateUtils::formatDate($p->date_start, ConstantsUtils::$DATE_FRIENDLY_FORMAT). " to " .DateUtils::formatDate($p->date_end, ConstantsUtils::$DATE_FRIENDLY_FORMAT) ;?></option>
	<?php endforeach;?>
	</select>
</div>
<div class="display_summary">
# Unreviewed: 100
</div>
<?php 
$regular_days = floor(abs(strtotime($p->date_end) - strtotime($p->date_start)) / (3600 * 24));

?>
<?php if(isset($timesheet)):?>
<table border="1" cellspacing="0" cellpadding="5" id="members" class="display">
<thead>
	<th>Employee Name</th>
	<th># Hours</th>
	<th>Reg Days</th>
	<th>Overtime(hr)</th>
	<th>Undertime(hr)</th>
	<th>Late(hr)</th>
	<th>Absenses</th>
	<th>Leave w/ Pay</th>
	<th>Leave w/o Pay</th>
	<?php if(isset($wrong_card) && count($wrong_card)>0):?>
	<th>Wrong Card</th>
	<?php endif;?>
	<th>Action</th>
</thead>
<?php foreach($timesheet as $ts) {
	$absent = $leavewpay = $leavewopay = $wrongcard = "--";
	$var_name = "uid".$ts->user_id;
	$abs = "\$absences->uid";
	$abs .= $ts->user_id;
	eval("\$n=".$abs.";");
	if(isset($n) && $n > 0) {
		$absent = $n;
	}
	
	// lwp
	$lwp = "\$leave_with_pay->uid";
	$lwp .= $ts->user_id;
	eval("\$n=".$lwp.";");
	if(isset($n) && $n > 0) {
		$leavewpay = $n;
	}
	
	// lwop
	$lwop = "\$leave_without_pay->uid";
	$lwop .= $ts->user_id;
	eval("\$n=".$lwop.";");
	if(isset($n) && $n > 0) {
		$leavewopay = $n;
	}
	
	// wrong card
	$wc = "\$wrong_card->uid";
	$wc .= $ts->user_id;
	eval("\$n=".$wc.";");
	if(isset($n) && $n > 0) {
		$wrongcard = $n;
	}
	
	$actual_days = $regular_days - floatval($absent) - floatval($leavewopay);
	
	
	?>
<tr class="timesheet_details" ts_id="<?php echo $ts->user_id;?>">
	<td><?php echo $ts->first_name?></td>
	<td><?php echo $ts->total_hours?></td>
	
	<td>
	<?php echo $actual_days;?>
	
	</td>
	
	<td><?php echo $ts->total_overtime?></td>
	<td><?php echo $ts->total_undertime?></td>
	
	
	<td><?php echo $ts->total_late?></td>
	<td>
	<?php 
		echo $absent;
	?>
	</td>
	<td>
	<?php 
		echo $leavewpay;
	?>
	
	</td>
	<td>
	<?php 
		echo $leavewopay;
	?>
	</td>
	<?php if(isset($wrong_card) && count($wrong_card)>0):?>
	<td>
	<?php 
	
		echo $wrongcard;
	?>
	</td>
	<?php endif;?>
	<td><a href="<?php echo base_url()?>timesheet/view_user/<?php echo $period->id; ?>/<?php echo $ts->user_id;?>" title="View/Edit"><img src="/images/common/edit_icon.png" border="0" ></a></td>
</tr>
<?php }?>
</table>
<?php endif;?>
</div>
<script language="javascript">
var path = "<?php echo base_url()?>timesheet/view_user/" + "<?php echo $period->id; ?>" + '/';
$(document).ready(function() {
	$('#members').dataTable({
		"sPaginationType": "full_numbers",
		"iDisplayLength":50
	});

	$("tr.timesheet_details").click(function(){
		var url = path + parseInt($(this).attr('ts_id'));
		document.location = url;
	});

	$('select#period').val("<?php echo $period->id?>");

	$("#period").change(function(){
		var url = "<?php echo base_url()?>timesheet/summary_period/" + parseInt($(this).val());
		document.location = url;
	})
	
} );
</script>
<?php 
	$time2 = CommonUtils::getCurrentTime();
	$diff = $time2 - $start_time;
	//echo "processed: " . $diff ." seconds";
?>